package com.ruoyi.mes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.domain.EquipmentAssets;
import com.ruoyi.mes.service.IEquipmentAssetsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备资产管理Controller
 * 
 * @author ruoyi
 * @date 2025-01-09
 */
@RestController
@RequestMapping("/mes/assets")
public class EquipmentAssetsController extends BaseController
{
    @Autowired
    private IEquipmentAssetsService equipmentAssetsService;

    /**
     * 查询设备资产管理列表
     */
    @PreAuthorize("@ss.hasPermi('mes:assets:list')")
    @GetMapping("/list")
    public TableDataInfo list(EquipmentAssets equipmentAssets)
    {
        startPage();
        List<EquipmentAssets> list = equipmentAssetsService.selectEquipmentAssetsList(equipmentAssets);
        return getDataTable(list);
    }

    /**
     * 导出设备资产管理列表
     */
    @PreAuthorize("@ss.hasPermi('mes:assets:export')")
    @Log(title = "设备资产管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EquipmentAssets equipmentAssets)
    {
        List<EquipmentAssets> list = equipmentAssetsService.selectEquipmentAssetsList(equipmentAssets);
        ExcelUtil<EquipmentAssets> util = new ExcelUtil<EquipmentAssets>(EquipmentAssets.class);
        util.exportExcel(response, list, "设备资产管理数据");
    }

    /**
     * 获取设备资产管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('mes:assets:query')")
    @GetMapping(value = "/{assetId}")
    public AjaxResult getInfo(@PathVariable("assetId") Long assetId)
    {
        return success(equipmentAssetsService.selectEquipmentAssetsByAssetId(assetId));
    }

    /**
     * 新增设备资产管理
     */
    @PreAuthorize("@ss.hasPermi('mes:assets:add')")
    @Log(title = "设备资产管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EquipmentAssets equipmentAssets)
    {
        return toAjax(equipmentAssetsService.insertEquipmentAssets(equipmentAssets));
    }

    /**
     * 修改设备资产管理
     */
    @PreAuthorize("@ss.hasPermi('mes:assets:edit')")
    @Log(title = "设备资产管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EquipmentAssets equipmentAssets)
    {
        return toAjax(equipmentAssetsService.updateEquipmentAssets(equipmentAssets));
    }

    /**
     * 删除设备资产管理
     */
    @PreAuthorize("@ss.hasPermi('mes:assets:remove')")
    @Log(title = "设备资产管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{assetIds}")
    public AjaxResult remove(@PathVariable Long[] assetIds)
    {
        return toAjax(equipmentAssetsService.deleteEquipmentAssetsByAssetIds(assetIds));
    }
}
